<!DOCTYPE html> 
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta charset="utf-8">
<title>账号设置</title>
<link href="jquery-mobile/jquery.mobile.min.css" rel="stylesheet" type="text/css"/>
<script src="jquery-mobile/jquery.min.js" type="text/javascript"></script>
<script src="jquery-mobile/jquery.mobile.min.js" type="text/javascript"></script>
<script src="js/cordova.js" type="text/javascript"></script>

<!--<script type="text/javascript"
src="http://qzonestyle.gtimg.cn/qzone/openapi/qc_loader.js" data-appid="100284268" data-redirecturi="http://ihavecar.sinaapp.com" charset="utf-8"></script>
-->
<style type="text/css">
#main {
	background:url("img/back.jpg") repeat;
}

#account {
	border-radius: 15px;
	border-style: solid;
	border-color: white;
	border-width: 1px;
	background-color: white;
	margin: 0 10px;
}

.center {
	text-align:center;
}
</style>

<script type="text/javascript">
function back(){
	if (typeof(navigator) != 'undefined' && typeof(navigator.app) != 'undefined' && typeof(navigator.app.backHistory) == 'function') {
		navigator.app.backHistory();
	} else{
		history.back();
	}
}

$(document).ready(function(){
	$("#logbox").css("min-height", document.body.clientHeight - $("#logbox").offset().top - $("#footer").height());
	$("#logbox").hide();
	$("#userinfo").hide();
	
	//getGPS();
	
	jQuery('body').live('swipeleft',function(event){
		back();
		//event.preventDefault();
	});
	jQuery('body').live('swiperight',function(event){
		window.history.forward();
		//event.preventDefault();
	});
});

$('.ui-btn-back').live('tap',function() {
	window.location.href ='index.html';
	return false;
}).live('click',function() {
	window.location.href ='index.html';
	return false;
});



</script>

</head>

<body>

<div id="main" data-role="page">
 <div data-role="header"  data-theme="b">
   <a href="#" class="ui-btn-back">主页</a>
   <!--<h1><a href="#" data-role="button">账号设置</a></h1>-->
   <h1>账号设置</h1>
 </div>
 
 
 <div id="userinfo">
 	<div id="nickimg"></div>
    <a href="#" onClick="logout()" data-role="button">注销账号</a>
   
   <div id="legal2">  
   <p style="text-align: right;">您可以随时关闭与合作平台的分享设置</p>
   </div>
 </div>
 
 <div data-role="content" id="logbox">
   <h1>快速登录</h1>
   <p>请使用新浪微博账号进行登录与绑定</p>
   <div id="account">
     <ul data-role="listview">
       <li><a id="sinalogin" onClick="sinalogin()">新浪微博</a></li>

     </ul>
   </div>
   
   <div id="legal1">  
   <p style="text-align: right;">您可以随时关闭与合作平台的分享设置</p>
   </br>
   </br>
   <p class="center">点击阅读隐私声明</p>
   <p class="center">如您选择登录即视为同意并愿意遵守原则</p>
 	</div>
 
 </div>
  




<script type="text/javascript">
    var access_token;
    var nickname;
    var image;
    var html;
    readfile();
function sinalogin(){
	//alert(access_token);
	window.location.href ='sinalogin.html';
}
function qqlogin(){
	//qq登录v1暂时不做
	window.location.href ='qqlogin.html';
}


//读取登录文件，若读取成功则认为已登录，显示已登录信息；反之显示登录框
function readfile() {
	document.addEventListener("deviceready", onDeviceReady, false);
    // PhoneGap is ready
    function onDeviceReady() {
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
    }

    function gotFS(fileSystem) {
        fileSystem.root.getFile("ucar/DataFile.txt", {create: true}, gotFileEntry, fail);
    }

    function gotFileEntry(fileEntry) {
        fileEntry.file(gotFile, fail);
    }

    function gotFile(file){
        readAsText(file);
    }

    function readAsText(file) {
				//alert("hello");
        var reader = new FileReader();
        reader.onloadend = function(evt) {
            //console.log("Read as text");
            //console.log(evt.target.result);
			var arg=evt.target.result.split(";");
			

            if (arg==""){
                // Empty file. Not Logined.
                $("#logbox").show();
            }else{
                //Read Loginfile
                var arg1=arg[0].split("=");
				var arg2=arg[1].split("=");
				var arg3=arg[2].split("=");
				var arg4=arg[3].split("=");
            
				access_token=arg2[1];
				nickname=arg3[1];
				image=arg4[1];

            html='<table>';
            html+='<tr><td><img src='+image+' width="60" 		height="60"></td>';
            html+='<td><b>'+nickname+' </b></td>';
            html+='</tr></table></br>';
            $('#nickimg').html(html);
            $("#userinfo").show();            
			}
        };
        reader.readAsText(file);	
		
		
    }

    function fail(evt) {
		$("#logbox").show();
		console.log("Detect as NOT logined.");
        console.log(evt.target.error.code);
    }
}

//注销账户，清空用户文件中的内容（暂时无法彻底删除）
function logout(fileEntry) {
    function fail(error) {
    	alert('Error Logout: ' + error.code);
	}

	// remove the file
    document.addEventListener("deviceready", onDeviceReady, false);
    
    function onDeviceReady() {
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
    }
    
    function gotFS(fileSystem) {
        fileSystem.root.getFile("ucar/DataFile.txt", {create: true}, gotFileEntry, fail);
    }
    
    function gotFileEntry(fileEntry){
    fileEntry.remove(success, fail);
        function success(fileEntry) {
            console.log("Removal succeeded");
            window.location.href ='login.html';
        }
        
        function fail(error) {
            alert('Error Logout: ' + error.code);
        }        
    }
}

</script>
</body>
</html>